// 1. 导入创建路由对象 和 创建hash对象
import { createRouter, createWebHashHistory } from 'vue-router';
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { loading } from '../utils/loading'
export const adminBaseRoutePath = '/'
// 3. 配置路由映射关系表h
const testroutes = [
  // 路径和组件映射起来
  { 
    name: 'layouts',
    path: '/', 
    meta: { 
      title: 'layouts',
      icon: 'el-icon-Menu',
      //keepalive: false,
      //menu_type: 'tab',
      //type: 'menu_dir',
      //addtab: true
    },
    component: () => import('../views/layouts/index.vue'),
    redirect:{name:"cshome"},
    children: [
      { 
        name: 'loading',
        path: 'loading:to?', 
        meta: { 
          title:'loading'
        },
        component: () => import('../views/loading.vue') 
      },
      { 
        name: 'cshome',
        path: '/cshome', 
        meta: { 
          title:'首页',
          addtab: true,
          keepalive: 'cshome',
        },
        component: () => import('../views/cshome.vue') 
      },
      { 
        name: 'appList',
        path: '/appList', 
        meta: { 
          title:'应用管理',
          icon: 'el-icon-Setting',
          keepalive: 'appList',
          menu_type: 'tab',
          type: 'menu',
          addtab: true
        },
        component: () => import('../views/backend/app/index.vue') 
      },
      { 
        name: 'roleList',
        path: '/roleList', 
        meta: { 
          title:'角色管理',
          icon: 'el-icon-Setting',
          keepalive: 'appList',
          menu_type: 'tab',
          type: 'menu',
          addtab: true
        },
        component: () => import('../views/backend/role/index.vue') 
      },
      { 
        name: 'userList',
        path: '/userList', 
        meta: { 
          title:'用户管理',
          icon: 'el-icon-Setting',
          keepalive: 'appList',
          menu_type: 'tab',
          type: 'menu',
          addtab: true
        },
        component: () => import('../views/backend/user/index.vue') 
      },
      { 
        name: 'fuguo',
        path: '/fuguo', 
        meta: { 
          title:'富国数据',
          icon: 'el-icon-Money',
          keepalive: 'fuguo',
          menu_type: 'tab',
          type: 'menu',
          addtab: true
        },
        component: () => import('../views/backend/share/fuguo.vue') 
      },
    ]
  },
  {
      path:'/login',
      name:'login',
      component:()=>import('../views/login.vue'),
      meta:{
          title:'登录'
      }
  },
  {
    // 404
    path: '/:path(.*)*',
    name: 'notFound',
    component: () => import('../views/common/404.vue'),
    meta: {
        title: `pagesTitle.notFound`, // 页面不存在
    },
  },
  
];



// 4. 创建路由对象
const router = createRouter({
  // 5. 配置路由跳转模式，这里使用 hash 模式
  history: createWebHashHistory(),
  // 把映射表放入
  routes:testroutes
});
router.beforeEach((to, from) => {
  NProgress.configure({ showSpinner: false })
  NProgress.start()
  if (!window.existLoading) {
    loading.show()
    window.existLoading = true
  }
  
})

// 路由加载后
router.afterEach(() => {
  if (window.existLoading) {
      loading.hide()
  }
  NProgress.done()
}) 
// 5. 导出
export default router;
